/*                                  ATELIER                                   */

/* %%LICENSE_TAG%%                                                            */
package edu.gmu.view.cube;

import edu.gmu.atelier.AffineVector;
import edu.gmu.atelier.AffineVectorFactory;
import edu.gmu.atelier.Matrix;
import edu.gmu.atelier.RealVector;
import edu.gmu.atelier.RealVectorFactory;
import edu.gmu.atelier.Vector;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import edu.gmu.view.canvas.Canvas;
import edu.gmu.view.canvas.CanvasPanel;
import java.util.ArrayList;
import java.util.List;

/**
 * The CubePanel displays cube tumbling through space.
 * @author  James H. Pope
 * @version $Revision:$ $Date:$
 */
public class EigenPanel extends JPanel
{
    /****************************  GUI components  ****************************/
    protected Canvas canvas = null;

    protected EigenLayer eigenLayer = null;

    /**
     * Creates a new instance of CubePanel
     * @param nodeModel
     */
    public EigenPanel( ControlModel controlModel )
    {   
    	BorderLayout mainLayout = new BorderLayout();
        this.setLayout( mainLayout );
        
        int frameRate = 1;
        this.canvas = new Canvas( frameRate );
        

//        this.cubeLayer   = new CubeLayer( controlModel );
//        cubeLayer.setName("Cube");
//        cubeLayer.setVisible(true);
//        this.canvas.getLayerModel().addLayer( cubeLayer );
        
        /*
         * Very cool Fibonacci series in matrix form - visualized!
         * 2 eigen values, 1.618034 and -0.618034, stretched in one
         * direction and dilates in the other.
         */
        List<Vector> v = new ArrayList<Vector>();
        v.add( new RealVector( 0.0, 1.0, 0.0) );
        v.add( new RealVector( 1.0, 1.0, 0.0) );
        v.add( new RealVector( 0.0, 0.0, 1.0) );
        
//        /*
//         * This one has eigen values 0.8 and 0.4, both dilate so unit
//         * circle shrinks to zero.
//         */
//        List<Vector> v = new ArrayList<Vector>();
//        v.add( new RealVector( 0.6, 0.2, 0.0) );
//        v.add( new RealVector( 0.2, 0.6, 0.0) );
//        v.add( new RealVector( 0.0, 0.0, 1.0) );
        
        /*
         * Make dependent rows - what happens?  As expected one eigen value
         * is zero and anilates the vectors in that direction, the other
         * happens to be 5.0 and so expands in that direction.
         * 
         * Interesting: Has to resemble a projection matrix
         */
        //List<Vector> v = new ArrayList<Vector>();
        //v.add( new RealVector( 1.0, 2.0) );
        //v.add( new RealVector( 2.0, 4.0) );
        
        /*
         * Three dimensions
         */
        //List<Vector> v = new ArrayList<Vector>();
        //v.add( new RealVector( 1.0, 1.0/2, 1.0/3) );
        //v.add( new RealVector( 0.0, 1.0, 1.0/2) );
        //v.add( new RealVector( 0.0, 0.0, 1.0) );
        
        //v.add( new RealVector(-3.0, 1.0, 6.0) );
        //v.add( new RealVector( 1.0,-1.0,-2.0) );
        //v.add( new RealVector(-1.0,-1.0, 0.0) );
        
        RealVectorFactory factory = new RealVectorFactory();
        Matrix m = new Matrix(v, factory);
        
        this.eigenLayer  = new EigenLayer( m, controlModel );
        eigenLayer.setName("Eigen");
        eigenLayer.setVisible(true);
        this.canvas.getLayerModel().addLayer( eigenLayer );
        
        
        
        CanvasPanel canvasPanel = new CanvasPanel( canvas );
        this.add( canvasPanel, BorderLayout.CENTER );
        
        this.canvas.start();
    }

    /**
     * Gets the canvas
     * @return canvas
     */
    public Canvas getCanvas()
    {
        return this.canvas;
    }
    
}

/*                                  ATELIER                                   */